package com.cn.ysf.newbeemall.service.Impl;

import com.cn.ysf.newbeemall.controller.vo.NewBeeMallIndexCarouselVO;
import com.cn.ysf.newbeemall.mapper.CarouselMapper;
import com.cn.ysf.newbeemall.pojo.TbNewbeeMallCarousel;
import com.cn.ysf.newbeemall.service.NewBeeMallCarouselService;
import com.cn.ysf.newbeemall.util.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ysf
 * @date 2019/12/3 19:18
 */
@Service
public class NewBeeMallCarouselServiceImpl implements NewBeeMallCarouselService {


    @Resource
    private CarouselMapper carouselMapper;

    @Override
    public TbNewbeeMallCarousel getCarouselById(Long id) {
        return carouselMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<NewBeeMallIndexCarouselVO> getCarouselsForIndex(Long number) {
        List<NewBeeMallIndexCarouselVO> newBeeMallIndexCarouselVOS=new ArrayList<>();
        List<TbNewbeeMallCarousel> tbNewbeeMallCarousels=carouselMapper.findCarouselsByNum(number);
        if(!CollectionUtils.isEmpty(tbNewbeeMallCarousels)){
            newBeeMallIndexCarouselVOS= BeanUtil.copyList(tbNewbeeMallCarousels,NewBeeMallIndexCarouselVO.class);
        }
        return newBeeMallIndexCarouselVOS;
    }
}
